package com.hmdp.utils;

import com.hmdp.entity.VoucherOrder;
import com.hmdp.service.IVoucherOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
public class SeckillOrderListener {

    @Autowired
    private IVoucherOrderService voucherOrderService;

    @RabbitListener(queues = "dianping.orders")
    public void handleSeckillOrder(List<Long> msg) {
        try {

            // 创建订单对象
            VoucherOrder order = new VoucherOrder();
            order.setId(msg.get(0));
            order.setUserId(msg.get(1));
            order.setVoucherId(msg.get(2));

//            voucherOrderService.createOrder(order);
            voucherOrderService.handleVoucherOrder(order);
        } catch (Exception e) {
            log.error("处理秒杀订单异常", e);
        }
    }
}
